package com.icim.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.icim.entity.Ret_prd_grd_info;
import com.icim.entity.Ret_prd_info;

@Repository
public class RetPrdGrdInfoDao {
    @Resource
    private JdbcTemplate icimJdbcTemplate;

    public List<Ret_prd_grd_info> getGrade(String prdSeqId) {
        String sql = "SELECT PRD_SEQ_ID_FK,PRD_SEQ_GRD FROM RET_PRD_GRD_INFO WHERE PRD_SEQ_ID_FK = ?";
        return icimJdbcTemplate.query(sql, new Object[] { prdSeqId }, new RowMapper<Ret_prd_grd_info>() {

            @Override
            public Ret_prd_grd_info mapRow(ResultSet rs, int rowNum) throws SQLException {
                Ret_prd_grd_info Ret_prd_grd_info = new Ret_prd_grd_info();
                Ret_prd_grd_info.setPrd_seq_id_fk(rs.getString("PRD_SEQ_ID_FK"));

                String grade = rs.getString("PRD_SEQ_GRD");
//                String ox = toOX(grade);
                Ret_prd_grd_info.setPrd_seq_grd(grade);
                return Ret_prd_grd_info;
            }
        });

    }

//    private String toOX(String grade) {
//        int cnt = grade.length();
//        StringBuffer buffer = new StringBuffer();
//        for (int i = 0; i < cnt; i++) {
//            char c = grade.charAt(i);
//            if (c == '0') {
//                buffer.append("O");
//            } else {
//                buffer.append("X");
//            }
//        }
//        return buffer.toString();
//    }
}
